package com.yitiao.data_algorithms.leetcode.editor.cn;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.ListNode;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

class CongWeiDaoTouDaYinLianBiaoLcof{
    //leetcode submit region begin(Prohibit modification and deletion)
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    // 递归
    List<Integer> list = new ArrayList<>();
    public int[] reversePrint(ListNode head) {
        recur(head);
        int[] ans = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            ans[i]=list.get(i);
        }
        return ans;
    }
    void recur(ListNode head)
    {
        if (head == null){
            return;
        }
        recur(head.next);
        list.add(head.val);
    }



    // 辅助栈
    private int[] getInts(ListNode head) {
        List<Integer> list = new ArrayList<>();
        Stack<Integer> stack = new Stack<>();
        if(head == null){
            return new int[0];
        }
        int i = 0;
        while (head !=null){
            stack.push(head.val);
            head = head.next;
            i++;

        }
        int[] ans = new int[i];
        i = 0;
        while (!stack.isEmpty()){
            ans[i]=stack.pop();
            i++;
        }
        return ans;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}